package com.ruoyi.web.controller.config;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.config.domain.TaskCategories;
import com.ruoyi.config.service.ITaskCategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 任务分类Controller
 * 
 * @author atzxc
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/config/categories")
public class TaskCategoriesController extends BaseController
{
    @Autowired
    private ITaskCategoriesService taskCategoriesService;

    /**
     * 查询任务分类列表
     */
    @PreAuthorize("@ss.hasPermi('config:categories:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskCategories taskCategories)
    {
        startPage();
        System.out.println("进来了雅");
        List<TaskCategories> list = taskCategoriesService.selectTaskCategoriesList(taskCategories);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出任务分类列表
     */
    @PreAuthorize("@ss.hasPermi('config:categories:export')")
    @Log(title = "任务分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskCategories taskCategories)
    {
        List<TaskCategories> list = taskCategoriesService.selectTaskCategoriesList(taskCategories);
        ExcelUtil<TaskCategories> util = new ExcelUtil<TaskCategories>(TaskCategories.class);
        util.exportExcel(response, list, "任务分类数据");
    }

    /**
     * 获取任务分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('config:categories:query')")
    @GetMapping(value = "/{CategoryId}")
    public AjaxResult getInfo(@PathVariable("CategoryId") Long CategoryId)
    {
        return success(taskCategoriesService.selectTaskCategoriesByCategoryId(CategoryId));
    }

    /**
     * 新增任务分类
     */
    @PreAuthorize("@ss.hasPermi('config:categories:add')")
    @Log(title = "任务分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskCategories taskCategories)
    {
        return toAjax(taskCategoriesService.insertTaskCategories(taskCategories));
    }

    /**
     * 修改任务分类
     */
    @PreAuthorize("@ss.hasPermi('config:categories:edit')")
    @Log(title = "任务分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskCategories taskCategories)
    {
        return toAjax(taskCategoriesService.updateTaskCategories(taskCategories));
    }

    /**
     * 删除任务分类
     */
    @PreAuthorize("@ss.hasPermi('config:categories:remove')")
    @Log(title = "任务分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{CategoryIds}")
    public AjaxResult remove(@PathVariable Long[] CategoryIds)
    {
        return toAjax(taskCategoriesService.deleteTaskCategoriesByCategoryIds(CategoryIds));
    }
}
